home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / DTML-TRY.STX < prev    next >
Encoding:
Text File  |  2000-10-12  |  2.6 KB  |  101 lines

  1. try: Handles exceptions
  2.  
  3.   The 'try' tag allows exception handling in DTML, mirroring the
  4.   Python 'try/except' and 'try/finally' constructs.
  5.  
  6.   Syntax
  7.  
  8.     The 'try' tag has two different syntaxes, 'try/except/else' and
  9.     'try/finally'.
  10.  
  11.     'try/except/else' Syntax::
  12.  
  13.       <dtml-try>
  14.     <dtml-except [ExceptionName] [ExceptionName]...>
  15.     ... 
  16.     [<dtml-else>]
  17.       </dtml-try>
  18.  
  19.     The 'try' tag encloses a block in which exceptions can be caught and
  20.     handled. There can be one or more 'except' tags that handles
  21.     zero or more exceptions. If a 'except' tag does not specify an
  22.     exception, then it handles all exceptions.
  23.  
  24.     When an exception is raised, control jumps to the first 'except'
  25.     tag that handles the exception. If there is no 'except' tag to
  26.     handled the exception, then the exception is raised normally.
  27.  
  28.     If no exception is raised, and there is an 'else' tag, then the
  29.     'else' tag will be executed after the body of the 'try' tag.
  30.  
  31.     The 'except' and 'else' tags are optional.
  32.  
  33.     'try/finally' Syntax::
  34.  
  35.       <dtml-try>
  36.     <dtml-finally>
  37.       </dtml-try>
  38.  
  39.     The 'finally' tag cannot be used in the same 'try' block as the
  40.     'except' and 'else' tags. If there is a 'finally' tag, its block
  41.     will be executed whether or not an exception is raised in the
  42.     'try' block.
  43.  
  44.   Attributes
  45.  
  46.     except -- Zero or more exception names. If no exceptions are
  47.     listed then the except tag will handle all exceptions.
  48.  
  49.   Tag Variables
  50.  
  51.     Inside the 'except' block these variables are defined.
  52.  
  53.       error_type -- The exception type.
  54.  
  55.       error_value -- The exception value.
  56.  
  57.       error_tb -- The traceback.
  58.  
  59.   Examples
  60.  
  61.     Catching a math error::
  62.  
  63.       <dtml-try>
  64.     <dtml-var expr="1/0">
  65.       <dtml-except ZeroDivisionError>
  66.     You tried to divide by zero.
  67.       </dtml-try>
  68.  
  69.     Returning information about the handled exception::
  70.  
  71.       <dtml-try>
  72.     <dtml-call dangerousMethod>
  73.       <dtml-except>
  74.     An error occurred.
  75.     Error type: <dtml-var error_type>
  76.     Error value: <dtml-var error_value>
  77.       </dtml-try>
  78.  
  79.     Using finally to make sure to perform clean up regardless
  80.     of whether an error is raised or not::
  81.  
  82.       <dtml-call acquireLock>
  83.       <dtml-try>
  84.     <dtml-call someMethod>
  85.       <dtml-finally>
  86.     <dtml-call releaseLock>
  87.       </dtml-try>
  88.  
  89.   See Also
  90.  
  91.     "raise tag":dtml-raise.stx
  92.  
  93.     "Python Tutorial: Errors and
  94.     Exceptions":http://www.python.org/doc/current/tut/node10.html
  95.  
  96.     "Python Bult-in
  97.     Exceptions":http://www.python.org/doc/current/lib/module-exceptions.html
  98.  
  99.  
  100.  
  101.